let PubSub = {
  id: 1,
  callbacks: {},
};


PubSub.subscribe = function (channel, callback) {
  let token = "token" + this.id++;

  if (this.callbacks[channel]) {
    this.callbacks[channel][token] = callback;
  } else {
    this.callbacks[channel] = {
      [token]: callback,
    };
  }
};


PubSub.publish = function (channel, data) {
  if (this.callbacks[channel]) {
    Object.values(this.callbacks[channel]).forEach((callback) => {
      callback(data);
    });
  }
};



